<%@ page import="com.party.core.model.system.TargetType" %>
<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="../include/tag.jsp" %>
<%@ taglib prefix="memberForm" uri="http://www.tongxingzhe.cn/memberForm" %>
<!DOCTYPE html>
<html lang="zh">
<head>
    <title>${project == null ? '发布' : '编辑'}项目</title>
    <%@include file="../include/commonFile.jsp" %>
    <link rel="stylesheet" href="${ctx}/css/common/list.css">
    <link rel="stylesheet" href="${ctx}/css/common/form.css">
    <link rel="stylesheet" href="${ctx}/css/ui/activity/publish_form.css">
</head>
<body>
<!--头部-->
<%@include file="../include/header.jsp" %>
<div class="index-outside">
    <%@include file="../include/sidebar.jsp" %>
    <!--内容-->
    <section>
        <div class="section-main">
            <!-- 正文请写在这里 -->
            <div class="add-form-content">
                <form id="myForm" class="layui-form mt20" method="post" action="${ctx}/gatherInfo/project/save.do">
                    <div class="layui-form-item">
                        <label class="layui-form-label">所属合作商<span class="f-verify-red">*</span></label>
                        <div class="layui-input-inline">
                            <input type="hidden" name="createBy" lay-verify="orgId"
                                   value="${project.createBy}"/>
                            <input type="text" id="member_name" value="${memberForm:getRealNameById(project.createBy)}"
                                   class="layui-input" readonly/>
                        </div>
                        <c:if test="${empty project.id}">
                            <a class="layui-btn layui-btn-danger" type="button"
                               onclick="openSelMemberDialog(this,'选择所属合作商','${ctx}/system/member/selectPartner.do','950px','570px')">
                                选择
                            </a>
                        </c:if>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">名称<span class="f-verify-red">*</span></label>
                        <div class="layui-input-block">
                            <input type="text" name="title" lay-verify="title" placeholder="项目名称" class="layui-input"
                                   value="${project.title}">
                            <input type="hidden" name="id" value="${project.id}"/>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">接送地点<span class="f-verify-red">*</span></label>
                        <div class="layui-input-block">
                            <input type="text" name="place" lay-verify="place" class="layui-input"
                                   value="${project.place}">
                        </div>
                    </div>
                    <div class="layui-form-item">

                        <label class="layui-form-label">基本信息描述<span class="f-verify-red">*</span></label>
                        <div class="layui-input-block">
                            <c:if test="${not empty project.baseInfoDesc || null != project.baseInfoDesc}">
                                <textarea name="baseInfoDesc" class="layui-textarea" lay-verify="required"
                                          placeholder="基本信息描述">${project.baseInfoDesc}</textarea>
                            </c:if>
                            <c:if test="${ empty project.baseInfoDesc || null == project.baseInfoDesc}">
                            <textarea name="baseInfoDesc" class="layui-textarea" lay-verify="required"
                                      placeholder="基本信息描述">请完善你的参赛个人基本信息，方便大家更好的认识你，也方便你和大家互相认识</textarea>
                            </c:if>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">保险信息描述<span class="f-verify-red">*</span></label>
                        <div class="layui-input-block">
                            <c:if test="${not empty project.insuranceInfoDesc || null != project.insuranceInfoDesc}">
                                <textarea name="insuranceInfoDesc" class="layui-textarea" lay-verify="required"
                                          placeholder="保险信息描述">${project.insuranceInfoDesc}</textarea>
                            </c:if>
                            <c:if test="${ empty project.insuranceInfoDesc || null == project.insuranceInfoDesc}">
                                <textarea name="insuranceInfoDesc" class="layui-textarea" lay-verify="required"
                                          placeholder="保险信息描述">请完善你个人的保险相关信息，方便赛事组委会为你购买保险，给你的参赛增加更多的保障</textarea>
                            </c:if>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">行程信息描述<span class="f-verify-red">*</span></label>
                        <div class="layui-input-block">
                            <c:if test="${not empty project.itineraryInfoDesc || null != project.itineraryInfoDesc}">
                                <textarea name="itineraryInfoDesc" class="layui-textarea" lay-verify="required"
                                          placeholder="行程信息描述">${project.itineraryInfoDesc}</textarea>
                            </c:if>
                            <c:if test="${ empty project.itineraryInfoDesc || null == project.itineraryInfoDesc}">
                                <textarea name="itineraryInfoDesc" class="layui-textarea" lay-verify="required"
                                          placeholder="行程信息描述">请完善你的交通出行信息，方便组委会接应您的行程</textarea>
                            </c:if>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">去程说明</label>
                        <div class="layui-input-block">
                            <c:if test="${not empty project.goDesc || null != project.goDesc}">
                                <textarea name="goDesc" class="layui-textarea"
                                          placeholder="去程说明">${project.goDesc}</textarea>
                            </c:if>
                            <c:if test="${ empty project.goDesc || null == project.goDesc}">
                                <textarea name="goDesc" class="layui-textarea" placeholder="去程说明">方便统计和协调各城市出发情况，以及到达时的接机</textarea>
                            </c:if>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">返程说明</label>
                        <div class="layui-input-block">
                            <c:if test="${not empty project.backDesc || null != project.backDesc}">
                                <textarea name="backDesc" class="layui-textarea"
                                          placeholder="返程描述">${project.backDesc}</textarea>
                            </c:if>
                            <c:if test="${ empty project.backDesc || null == project.backDesc}">
                                <textarea name="backDesc" class="layui-textarea"
                                          placeholder="返程描述">方便统计出发时间，便于组委会送机</textarea>
                            </c:if>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">住宿说明</label>
                        <div class="layui-input-block">
                            <c:if test="${not empty project.lodgingDesc || null != project.lodgingDesc}">
                                <textarea name="lodgingDesc" class="layui-textarea" placeholder="住宿说明">${project.lodgingDesc}</textarea>
                            </c:if>
                            <c:if test="${ empty project.lodgingDesc || null == project.lodgingDesc}">
							<textarea name="lodgingDesc" class="layui-textarea" placeholder="住宿说明">
                                1.组委会统一安排出征仪式晚上和庆功宴晚上的四星级酒店标间住宿，如需安排单间，需补房费2.提前到达戈友如需，组委会可以协助在活动酒店预定房间</textarea>
                            </c:if>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <a href="javascript:void(0)" class="layui-btn layui-btn-danger" lay-submit lay-filter="*">立即提交</a>
                            <a href="${ctx}/gatherInfo/project/list.do" class="layui-btn layui-btn-primary">取消</a>
                        </div>
                    </div>
                </form>
            </div>
        </div>
        <!--底部-->
        <%@include file="../include/footer.jsp" %>
        <c:if test="${not empty project.createBy}">
            <c:set var="isExpire" value="${memberForm:isExpire(project.createBy, null)}"/>
        </c:if>
    </section>
</div>

<script>
    $(function () {
        layui.use(['form'], function () {
            var form = layui.form;

            //自定义验证规则
            form.verify({
                orgId: function (value) {
                    if (!value) {
                        return "请选择所属合作商"
                    }
                    if ('${isExpire}' == 'true' && '${project.id}' == '') {
                        return "当前合作商已到期，不能发布数据"
                    }
                },
                title: function (value) {
                    if (value == "") {
                        return '请填写项目名称';
                    }
                }
            });

            //监听提交
            form.on('submit', function (data) {
                txz.submitObject(data.elem, function (callBack) {
                    var action = $("#myForm").attr("action");
                    $.post(action, $('#myForm').serialize(), function (res) {
                        typeof callBack === 'function' && callBack();
                        if (res.success) {
                            util.layerMsgSuccess("提交成功", function () {
                                location.href = "${ctx}/gatherInfo/project/list.do";
                            });
                        } else {
                            util.layerMsgError("提交失败")
                        }
                    });
                });
                return false;
            });
        });
        $('#sel_pic_img').click(function () {
            txz.openSelImg({
                min: 1,
                max: 1,
                info: '建议尺寸：800x450',
                type: '<%=TargetType.GATHER_INFO.getCode()%>',
                cb: function (imgs) {
                    $('#cover-img').css('background-image', 'url(' + imgs[0].path + ')');
                    $('#pic').val(imgs[0].path);
                }
            })
        })
    })

    function openSelMemberDialog(that, title, url, width, height) {
        txz.openDialogIframe({
            width: width,
            height: height,
            title: title,
            url: url,
            cb: function (opt) {
                var content = opt.content;
                if (content.doSubmit()) {
                    var data = content.returnData();
                    $('input[name=createBy]').val(data.id);
                    $('#member_name').val(data.name);
                    top.layer.close(opt.index);
                }
            }
        })
    }
</script>
<script type="text/javascript">
    txz.initHeader({
        nav: [{
            name: '项目管理',
            href: '${ctx}/gatherInfo/project/list.do'
        }, {
            name: '${project == null ? '发布' : '编辑'}项目',
            curr: true
        }],
        btns: [{
            name: '返回',
            href: 'javascript:history.back();',
            icon: 'back'
        }]
    });
</script>
</body>
</html>